import $store from '@/store/index.js';
import groupSqlite from "@/sqlite_services/group.js"
//群禁言某个人
const handle = async(data)=>{
	try{
		
		const activeChatUuid = $store.state.chat.chatInfo && $store.state.chat.chatInfo.uuid || ''; // 访问根级状态的chatInfo
		//如果在群里
		if(data.target_id == activeChatUuid){
			let myid = $store.state.user.user_info.user_id
			let updataMember = []//需要更新的群成员
			
			data.members.forEach((key) => {
				  //本人
				  if(key == myid){
					$store.commit('updateChatGroupInfo',{
						group_id:data.target_id,
						userMuted:1
					})
					groupSqlite.editGroupInfo(data.target_id,{
						userMuted:1
					})
				  }
				  //全部放进去，不管是不是自己
				  updataMember.push({
					user_id: key, 
					is_muted:1
				  })
			});
			$store.commit('updateGroupMembersInfo',{
				group_id:data.target_id,
				data:updataMember
			})
			//发送全局通知
			uni.$emit('onGroupMemberAction',{
				type:'muted',
				data:{
					group_id:data.target_id,
					user_ids:data.members
				}
			})
		}else{
			let myid = $store.state.user.user_info.user_id
			data.members.forEach((key) => {
				  //本人
				  if(key == myid){
				  	groupSqlite.editGroupInfo(data.target_id,{
				  		userMuted:1
				  	})
				  }
			});
			//然后更新其他群成员
		}
	}catch(e){
		
	}
}
export default handle